import EChart from './baseECharts';
import settings from '../../config/settings';
/**
 * opt:
 * el dom  必传
 */
export default class FaultPie extends EChart {

    /**
     * 设置值.
     * @param {Oject} data
     * title 报警分类
     * titleColor : '#0482BE',
     * titleSize : 1
     * list:[{
     *  color:'#00A0E9',
     *  value : 24,
     *  name : '用电'
     * }]
     */
    setData(data) {
        let option = {
            title: {
                text: data.title,
                x: 'center',
                y: 'center',
                textStyle: {
                    fontWeight: 'normal',
                    color: data.titleColor || '#0482BE',
                    fontSize: (data.titleSize || 0.2) * settings.BASE_SIZE
                }
            },
            tooltip: {
                trigger: 'item',
                formatter: function(params, ticket, callback) {
                    var res = params.seriesName;
                    res += '<br/>' + params.name + ' : ' + params.percent + '%';
                    return res;
                },
                textStyle: {
                    fontSize: (data.titleSize || 0.2) * settings.BASE_SIZE
                }
            },
            series: [
                {
                    name: data.title,
                    type: 'pie',
                    selectedMode: 'single',
                    radius: ['40%', '60%'],
                    color: data.list.map(t => t.color),
                    label: {
                        normal: {
                            formatter: '{c}',
                            fontSize:
                                (data.titleSize || 0.2) * settings.BASE_SIZE,
                            color: data.titleColor || '#0482BE'
                        }
                    },
                    labelLine: {
                        normal: {
                            show: false
                        }
                    },
                    data: data.list
                }
            ]
        };
        this.setOption(option);
    }

}
